(function(){
	angular.module("zhuceCtrlModule",[])
		.controller("zhuceController",["$scope",
            "postDataService","messageService",
            "modalDataService","USERDATA","$rootScope",
            "$ionicModal","getDataService","$http","$ionicLoading","HOST",
            function($scope,postDataService,
                     messageService,
                     modalDataService,
                     USERDATA,
                     $rootScope,
                     $ionicModal,
                     getDataService,
                     $http,$ionicLoading,
                     HOST
                     ){
                $scope.user = {};
                $scope.user = {};
                    // 用户名
                $scope.nameBlur = function(){
                    // console.log(event);
                    if(/^\w{6,12}$/.test($scope.user.name)){
                        // console.log(1);
                        // 判断是否有该用户
                        getDataService.getRequest("userInfoLogin.php",
                            {u_name:$scope.user.name},
                            function(data){
                                // console.log(data);
                                if(data.code == 1){
                                    $ionicLoading.show({
                                        template: '用户名已存在!',
                                        duration: 1000
                                    });
                                }else{
                                    // console.log(data.data);
                                }
                            },
                            function(error){
                                // console.log(error);
                            }
                        )
                    }else{
                        $ionicLoading.show({
                            template: '用户名格式不正确',
                            duration: 1000
                        });
                    }
                }
                    // 密码
                $scope.pswBlur = function(){
                    if(/^\w{6,12}$/.test($scope.user.psw)){
                        // console.log(1);
                    }else{
                        $ionicLoading.show({
                            template: '密码格式不正确',
                            duration: 1000
                        });
                    }
                }
                    // 重复密码
                $scope.rePswBlur = function(){
                    if($scope.user.psw == $scope.user.repsw){
                        // console.log(1);
                    }else{
                        $ionicLoading.show({
                            template: '密码错误',
                            duration: 1000
                        });
                    }
                }
                    // 电话
                $scope.telBlur = function(){
                    if(/^1[3578]\d{9}$/.test($scope.user.tel)){
                        // console.log(1);
                    }else{
                        $ionicLoading.show({
                            template: '电话格式不正确',
                            duration: 1000
                        });
                    }
                }
                $scope.zhuceCtrlData = function(){
                    $rootScope.loadingText = "正在注册 . . .";
                    $rootScope.loading = true;
                    $http.post(HOST+"suerInfozhuce.php",
                        "username="+$scope.user.name+"&"+
                            "userpsw="+hex_md5($scope.user.psw)+"&"+
                            "usertel="+$scope.user.tel,
                        {headers:
                            {"Content-type":"application/x-www-form-urlencoded"}}
                        ).success(function(data){
                            $rootScope.loading = false;
                            // console.log(data);
                            $ionicLoading.show({
                                template: data.data,
                                duration: 1500
                            
                            });
                            modalDataService.myModal.hide();
                        }).error(function(){
                            $rootScope.loading = false;
                            // console.log(error);
                            $ionicLoading.show({
                                template: error,
                                duration: 1500
                            });
                        });
                }

                $scope.FanHui = function(){
                    console.log(11);
                    modalDataService.myModal.hide();
                }

                $scope.loginIn = function(){
                    $ionicModal.fromTemplateUrl('tpl/login.html', {
                        animation: 'slide-in-up'
                    }).then(function(modal) {
                        $scope.modal = modal;
                        modalDataService.myModal = modal;
                        $scope.modal.show();

                    });
                    modalDataService.myModal.hide();
                };
        }])
})();
// 注册验证
                